package com.zzr.zzrbackend.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class RecommendVolunteerType {
    public List<String> getRecommend(Integer id) {
        List<String> snList = null;
        try {
            //Python解释器
//            String s1 = "D:\\GameDownload\\Surprise-master\\Surprise-master\\venv\\Scripts\\python.exe";
            String s1 = "/usr/local/bin/python3";
//            String s1 = "/Users/yuleng/Documents/DEV/Anaconda/anaconda3/envs/mocking/bin/python";
            String[] args1 = new String[]{s1, "RecommendVolunteerPY.py", String.valueOf(id)};
//            String[] args1 = new String[]{s1, "src/main/java/com/zzr/zzrbackend/util/RecommendVolunteerPY.py", String.valueOf(id)};
            Process proc = Runtime.getRuntime().exec(args1);// 执行py文件
            //用输入输出流来截取结果
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line;
            String ids = null;
            while ((line = in.readLine()) != null) {
                ids = line;
            }
            if (ids != null) {
                snList = Arrays.asList(ids.split(","));
            }else {
                return null;
            }

            in.close();
            proc.waitFor();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }

        return snList;
    }
}